package com.example.myapp.getui;

import com.example.myapp.MainActivity;
import com.igexin.sdk.GTIntentService;
import com.igexin.sdk.PushManager;
import com.igexin.sdk.message.GTCmdMessage;
import com.igexin.sdk.message.GTTransmitMessage;

import android.content.Context;
import android.os.Message;
import android.util.Log;

public class DemoIntentService extends GTIntentService {
	public DemoIntentService() {

	}

	@Override
	public void onReceiveServicePid(Context context, int pid) {
	}

	@Override
	public void onReceiveMessageData(Context context, GTTransmitMessage msg) {
        String appid = msg.getAppid();
        String taskid = msg.getTaskId();
        String messageid = msg.getMessageId();
        byte[] payload = msg.getPayload();
        String pkg = msg.getPkgName();
        String cid = msg.getClientId();
        System.out.println("appid--->>"+appid);
        System.out.println("pkg--->>"+pkg);
        System.out.println("cid--->>"+cid);
        boolean result = PushManager.getInstance().sendFeedbackMessage(context, taskid, messageid, 90001);
        Log.d(TAG, "call sendFeedbackMessage = " + (result ? "success" : "failed"));
        if (payload == null) {
        } else {
            String data = new String(payload);
            sendMessage(data, 0);
            System.out.println("data-------->"+data);
        }
	}

	@Override
	public void onReceiveClientId(Context context, String clientid) {
		Log.e(TAG, "onReceiveClientId -> " + "clientid = " + clientid);
	}
// b01e6eb4449f7ea2282116faec87d53e

	@Override
	public void onReceiveOnlineState(Context context, boolean online) {
	}

	@Override
	public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) {
	}
    private void sendMessage(String data, int what) {
        Message msg = Message.obtain();
        msg.what = what;
        msg.obj = data;
        MainActivity.sendMessage(msg);
        Log.e(TAG, "sendMessage: sendMessage" );
    }
}
